package com.dap.batch.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.ReferenceBean;
import com.dap.batch.dao.IDaoService;
import com.dap.batch.service.IBatchGroupService;
import com.dap.batch.service.IBatchJobService;
import com.dap.batch.service.IBatchSchedulerBroker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 消费服务创建，通过硬编码方式实现
 * @author: Fesine
 * @createTime:2017/9/14 23:07
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/9/14 23:07
 */
@Configuration
public class BatchReferConfig extends DubboBaseConfig {

    @Autowired
    private ApplicationConfig app;
    @Autowired
    private RegistryConfig registry;

    @Bean
    public IBatchGroupService groupService(){
        ReferenceBean<IBatchGroupService> ref = new ReferenceBean<>();
        ref.setInterface(IBatchGroupService.class);
        this.initRef(ref, "batchGroupService");
        return ref.get();
    }
    @Bean
    public IBatchJobService jobService(){
        ReferenceBean<IBatchJobService> ref = new ReferenceBean<>();
        ref.setInterface(IBatchJobService.class);
        this.initRef(ref, "batchJobService");
        return ref.get();
    }
    @Bean
    public IBatchSchedulerBroker schedulerBroker(){
        ReferenceBean<IBatchSchedulerBroker> ref = new ReferenceBean<>();
        ref.setInterface(IBatchSchedulerBroker.class);
        this.initRef(ref, "batchSchedulerBroker");
        return ref.get();
    }

    @Bean
    public IDaoService daoService(){
        ReferenceBean<IDaoService> ref = new ReferenceBean<>();
        ref.setInterface(IDaoService.class);
        this.initRef(ref, "batchDaoService");
        return ref.get();
    }

    private void initRef(ReferenceBean ref,String group) {
        ref.setRegistry(registry);
        ref.setApplication(app);
        ref.setGroup(group);
        ref.setTimeout(5000);
        ref.setRetries(3);
        ref.setCheck(false);
    }



}
